package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.BaseUser;
import com.briup.jz.bean.BaseUserExample;
import com.briup.jz.bean.extend.BaseUserExtend;
import com.briup.jz.dao.BaseUserMapper;
import com.briup.jz.dao.BaseUserRoleMapper;
import com.briup.jz.dao.extend.BaseUserExtendMapper;
import com.briup.jz.service.BaseUserService;
import com.briup.jz.utils.CustomerException;

@Service
public class BaseUserServiceImpl implements BaseUserService {

	@Autowired
	private BaseUserMapper baseUserMapper;
	@Autowired
	private BaseUserExtendMapper baseUserExtendMapper;
	@Autowired
	private BaseUserRoleMapper baseUserRoleMapper;
	@Override
	public void deleteById(long id) throws CustomerException {
		BaseUser baseUser = baseUserMapper.selectByPrimaryKey(id);
		if (baseUser == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		baseUserMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void saveOrUpdate(BaseUser baseUser) throws CustomerException {
		if (baseUser.getId() != null) {
			baseUserMapper.updateByPrimaryKey(baseUser);
		} else {
			baseUserMapper.insert(baseUser);
		}
	}

	@Override
	public List<BaseUser> query(String name) {
		BaseUserExample example = new BaseUserExample();
		if (name != null) {
			example.createCriteria().andRealnameLike("%" + name + "%");
		}
		List<BaseUser> list = baseUserMapper.selectByExample(example);
		return list;
	}

	@Override
	public List<BaseUserExtend> selectUserRole(String userName, String status, String roleName) {
		return baseUserExtendMapper.selectUserRole(userName, status, roleName);
	}

	@Override
	public List<BaseUser> selectAllStatus() {
		BaseUserExample example = new BaseUserExample();
		return baseUserMapper.selectAllStatus(example);
	}


}
